package com.natasha.pins.view.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.natasha.pins.R;
import com.natasha.pins.bh.pinsmaster.PinsMasterBH;
import com.natasha.pins.data.bean.PinsMasterBean;
import com.natasha.pins.view.holder.PinsMasterBeanHolder;

public class AdptrPinBean extends ArrayAdapter<PinsMasterBean>{
	
//	private Context context;
	private int layoutResourceId;
//	private List<PinsMasterBean> data=null;
//	private PinsMasterBH pinsMasterBH;
	
	public AdptrPinBean(Context context, int layoutResourceId, List<PinsMasterBean> data) {
		super(context, layoutResourceId, data);
//		this.context = context;
		this.layoutResourceId = layoutResourceId;
//		this.data = data;
		//fillData();
	}
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		View row = convertView;
		PinsMasterBeanHolder holder = null;
		PinsMasterBean pinsMasterBean;
		
		if( row == null){
			LayoutInflater layoutInflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			row = layoutInflater.inflate(layoutResourceId, null);
			
			holder = new PinsMasterBeanHolder();
			holder.setTvPinTitle((TextView) row.findViewById(R.id.tvPinTitle));
			holder.setTvPinWhen((TextView) row.findViewById(R.id.tvPinWhen));
			holder.setTvPinComment((TextView) row.findViewById(R.id.tvPinComment));
			holder.setTvPinMultimedia((TextView) row.findViewById(R.id.tvPinMultimedia));
			
			row.setTag(holder);
		}
		else{
			holder = (PinsMasterBeanHolder) row.getTag();
		}
		
//		pinsMasterBean = (PinsMasterBean) getItem(position);
//		holder.getTvPinTitle().setText(pinsMasterBean.getPmtitle());
//		holder.getTvPinWhen().setText(pinsMasterBean.getStringPmwhendt());
//		holder.getTvPinComment().setText(pinsMasterBean.getPmdetail());
//		holder.getTvPinMultimedia().setText(pinsMasterBean.getPmmedia());
		
		holder.getTvPinTitle().setText(getItem(position).getPmtitle());
		holder.getTvPinWhen().setText(getItem(position).getStringPmwhendt());
		holder.getTvPinComment().setText(getItem(position).getPmdetail());
		holder.getTvPinMultimedia().setText(getItem(position).getPmmedia());
		
		return row;
	}
	
	/*
	public void refreshData(){
		pinsMasterBH = new PinsMasterBH(context);
		
		pinsMasterBH.fetchAllPins();
		data = pinsMasterBH.getPinsMasterBeanList();
		notifyDataSetChanged();
	}

	public void setData(List<PinsMasterBean> data) {
		this.data = data;
	}*/
	
	/*
	public void fillData(){
		pinsMasterBH = new PinsMasterBH(context);
		
		Cursor cursor = pinsMasterBH.fetchAllPins();
		context.startManagingCursor(cursor);
		
		//create an array to specify the fields we want (only the title)
		String[] from = new String[]{PinsMasterBean.NAME_PMTITLE};
		
		//and an array of the fields we want to bind in the view
		int[] to = new int[]{R.id.tvPinTitle};
		
		//now create a simple cursor adapter and set it to display
		SimpleCursorAdapter simpleCursorAdapter = new SimpleCursorAdapter(context, R.layout.pin_bean, cursor, from, to);
		pinsCursorAdapter = simpleCursorAdapter;
	}*/
	
	/*
	public SimpleCursorAdapter getPinsCursorAdapter() {
		return pinsCursorAdapter;
	}*/
}
